package cn.hesion.leetcode;
/**
 * ClassName: CanConstruct <br/>
 * Description: <br/>
 * date: 2022/5/14 7:48<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author: hesion
 * @create: 2022-05-14 07:48
 **/
public class CanConstruct {
    public boolean canConstruct(String s, int k){
        if(s.length()==k){
            return true;
        }else if(s.length() < k){
            return false;
        }
        int n = s.length();
        HashMap<Character, Integer> charMap = new HashMap<>();
        int count=0;
        for (int i = 0; i < n; i++) {
            charMap.put(s.charAt(i),charMap.getOrDefault(s.charAt(i),0)+1);
        }
        for (Map.Entry<Character, Integer> characterIntegerEntry : charMap.entrySet()) {
            Integer value = characterIntegerEntry.getValue();
            if(value%2==1){
                count++;
            }
        }
        if(count<=k){
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new CanConstruct().canConstruct("cr",7));
    }
}
